package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	router := gin.Default()
	router.LoadHTMLFiles("./login.html", "./index.html", "./home.html")
	router.GET("/login", func(c *gin.Context) {
		c.HTML(http.StatusOK, "login.html", nil)
	})

	router.GET("/home", func(c *gin.Context) {
		username := c.DefaultPostForm("username", "Mike")
		password := c.DefaultPostForm("password", "123456")
		c.HTML(http.StatusOK, "home.html", gin.H{
				"user" : username,
				"psw":password,
		})
	})
	router.POST("/login", func(c *gin.Context) {
		username := c.PostForm("username")
		password := c.PostForm("password")
		if password != "123456" {
			c.Param("密码错误")
		} else {
			c.HTML(http.StatusOK, "index.html", gin.H{
				"name": username,
				"password": password,
			})
		}
	})

	router.Run(":9000")
}
